package cn.com.utt.unms.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import cn.com.utt.unms.vo.AccountInfo;

@Mapper
public interface AccountMapper {
	
	@Insert("insert into user(email,username,password,group_id,parent_id,remark,create_time)values(#{email},#{username},#{password},#{groupId},#{parentId},#{remark},now())")
	@Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
	void save(AccountInfo accountInfo);
	
	@Update("update user set email=#{email},username=#{username},password=#{password},group_id=#{groupId},remark=#{remark},last_reset_date=now() where id=#{id}")
	void update(AccountInfo accountInfo);
	
	@Update({"<script>",
	    "update `user` set group_id=#{groupId} ", 
	    "WHERE ", 
	    "id IN", 
	      "<foreach item='item' index='index' collection='userIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	void updateGroupIdByUserIds(@Param("userIds")List<Long> userIds,@Param("groupId")long groupId);
	
}
